use directories::{ProjectDirs, UserDirs};
use lazy_static::lazy_static;

pub struct Util {}

const QUALIFIER: &str = "com";
const ORGANIZATION: &str = "beargod";
const APP_NAME: &str = "dhomer";

lazy_static! {
    static ref APP_DIRS: ProjectDirs =
        ProjectDirs::from(QUALIFIER, ORGANIZATION, APP_NAME).expect("Can not get app directories");
    static ref USER_DIRS: UserDirs = UserDirs::new().expect("Can not get user directories");
}

impl Util {
    pub fn app_name() -> String {
        APP_NAME.to_string()
    }
    pub fn app_dirs() -> &'static ProjectDirs {
        &(APP_DIRS)
    }

    pub fn user_dirs() -> &'static UserDirs {
        &(USER_DIRS)
    }
}

#[cfg(test)]
mod test {
    use crate::{c::CONFIG_FILE_NAME, util::Util};

    #[test]
    fn print_config_path() {
        let p = Util::app_dirs().config_dir().join(CONFIG_FILE_NAME);
        println!("{}", p.display());
    }
}